# -------- Build Stage --------
FROM python:3.12-slim AS builder

# 安装构建依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ make \
    libssl-dev libffi-dev \
    libxml2-dev libxslt1-dev zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

# 升级 pip
RUN pip install --no-cache-dir --upgrade pip

WORKDIR /app

# 拷贝依赖文件并安装到临时目录
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt


# -------- Runtime Stage --------
FROM python:3.12-slim

# 安装运行时依赖（cron、时区）
RUN apt-get update && apt-get install -y --no-install-recommends \
    cron tzdata ca-certificates \
    && rm -rf /var/lib/apt/lists/*

ENV TZ=Asia/Shanghai
WORKDIR /app

# 从 builder 拷贝已安装的依赖
COPY --from=builder /install /usr/local

# 拷贝项目代码
COPY . .

# 确保 entrypoint.sh 可执行
RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]
